package demo.controller;

import java.time.LocalDateTime;
import java.util.concurrent.Future;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import demo.bean.AsyncBean;

@RestController
@RequestMapping("/async")
public class AsyncController {

	@Autowired
	AsyncBean asyncBean;
	
	@RequestMapping({"/noResult"})
	public String doNoResult() {
		String str = "AsyncController.doNoResult start="+LocalDateTime.now();
		asyncBean.doNoResult();
	    str = str + ",done="+LocalDateTime.now();
	    return str;
	}
	
	@RequestMapping({"/hasResult"})
	public String doHasResult() throws Exception{
		String str = "AsyncController.doHasResult start="+LocalDateTime.now();
		Future<String> f = asyncBean.doHasResult();
		str = str +",getFuture "+LocalDateTime.now();
		str = str +",result="+f.get();
		str = str +"########done="+LocalDateTime.now();		
	    return str;
	}


}